
package ClientGraphics;

import java.awt.image.BufferedImage;

/**
 *
 * @author mhfowler
 */
public class Animation {

    int animationCount;
    int numAnimations;
    ImageWrapper[] imgs;
    boolean repeating;

    public Animation(int numImgs, boolean r) {
        imgs = new ImageWrapper[numImgs];
        numAnimations = numImgs;
        repeating = r;
    }

    public void addImage(ImageWrapper wrapper, int index) {
        imgs[index] = wrapper;
        animationCount = 0;
    }

    public ImageWrapper getImage() {
        int c = animationCount;
        // check if you're still in cycle
        if (animationCount < (numAnimations - 1)) {
            animationCount++;
        } // else either reset cycle or hang on last frame
        else {
            if (repeating) {
                animationCount = 0;
            }
        }
        return imgs[c];
    }

}
